#!/usr/bin/python -u
#-*- coding: UTF-8 -*-
import subprocess
import MySQLdb
import os
import re
import sys
import time
import statvfs

ip="114.80.213.44"
ping = subprocess.Popen(["ping", "-c", "2", "-w", "500", ip], shell=False)
ping.wait()
if ping.returncode != 0:
    #print ping.returncode, "ERROR: failed to ping host. Please check."
    conn = MySQLdb.connect(host='localhost',port=3306,user='root',passwd='root')
    cursor=conn.cursor()
    conn.select_db('os')
    sql = "insert into down(datetime) values(%s)"
    param = (time.strftime('%Y-%m-%d',time.localtime(time.time())))
    n = cursor.execute(sql,param)
    print n
    cursor.close()
    sys.exit(1)
else:
    print "OK"

